﻿/*!	r_rtti_reflection_typebase.h
	@brief	RTTIプロパティ
Copyright (c) 2009 Yuya Yamaguchi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef _R_RTTI_REFLECTION_TYPEBASE_H_
#define _R_RTTI_REFLECTION_TYPEBASE_H_

#include "../r_type.h"
#include "../util/r_util_stdstring.h"

namespace r{
	namespace rtti{
		///
		/*! このクラスのXMLベースのシリアライズ実行の為にMiXライブラリが必要になります
		*/
		class ReflectionTypeBase
		{
			template<class Archive, class T>friend void serializeCall( Archive& ar, T val, void* _this );
			template<class>friend class ReflectionType;
		public:
			ReflectionTypeBase()
				:
				valName ( NULL ),
				offset ( 0 ),
				hint ( NULL ),
				flag ( 0 ),
				length ( 0 )
			{}
			ReflectionTypeBase ( const r_cstr _valName, r_ui32 _offset, const r_cstr _hint, r_ui32 _flag, r_ui32 _length = 0 )
				:
				valName ( _valName ),
				offset ( _offset ),
				hint ( _hint ),
				flag ( _flag ),
				length ( _length ) {}
		public:
			void*					getAddr ( const void* r ) const {
				return reinterpret_cast<void*> ( reinterpret_cast<r_size> ( r ) + offset );
			}
			//! サイズの取得
			virtual	r_size			getSize() const {
				return 0;
			}
			//! 型名の取得
			virtual	const r_cstr	getTypeName() const {
				return NULL;
			}
			//! 変数名の取得
			virtual	const r_cstr	getValueName() const {
				return valName;
			}
			//! ヒントの取得
			virtual	const r_cstr	getHint() const {
				return hint;
			}
		public:
		protected:
			const r_cstr			valName;
			const r_cstr			hint;
			r_ui32					flag;
			r_ui32					offset;
			r_ui32					length;
		};

	}
}
#endif // _R_RTTI_REFLECTION_TYPEBASE_H_
